import { test, expect } from 'bun:test'
/* 自行创建 */
import { scriptToken, webhookURL } from './const-value.ignore'
import { initRemoteCallWpsjsGlobal } from '../index'

test('表 创建', async () => {
  const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL, printLog: true })
  const randomString = Math.random().toFixed(2).split('.')[1]
  const info = await wpsjsGlobal.Application.Sheet.CreateSheet({
    Name: `表格${randomString}`,
    Views: [{ name: '表格', type: 'Grid' }],
    Fields: [{ name: '名称', type: 'MultiLineText' }],
  }).execution()
  const keys = [
    'id',
    'fields',
    'name',
    'primaryFieldId',
    'views',
  ]
  expect(Object.keys(info)).toEqual(expect.arrayContaining(keys))
})

test('表 获取', async () => {
  const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL, printLog: true })
  const infoArray = await wpsjsGlobal.Application.Sheet.GetSheets().execution()
  const info = infoArray[0]
  const keys = [
    'id',
    'fields',
    'name',
    'primaryFieldId',
    'views',
  ]
  expect(Object.keys(info)).toEqual(expect.arrayContaining(keys))
})

test('表 更新', async () => {
  const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL })
  const randomString = Math.random().toFixed(2).split('.')[1]
  const result = await wpsjsGlobal.Application.Sheet.UpdateSheet({ SheetId: 1, Name: `表格${randomString}` }).execution()
  expect(result).toBeTrue()
})


test('表 删除', async () => {
  const wpsjsGlobal = initRemoteCallWpsjsGlobal({ scriptToken, webhookURL })
  const info = await wpsjsGlobal.Application.Sheet.DeleteSheet({ SheetId: 8 }).execution()
  expect(info).toHaveProperty('id')
})
